home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-01 / msoftapp.zip / VIEWER.CPP < prev    next >
C/C++ Source or Header  |  1993-06-01  |  4KB  |  148 lines

  1. // viewer.cpp : Defines the class behaviors for the MDI sample application.
  2.  
  3. #include"viewer.h"
  4.  
  5. COLORREF clrTextArray[5] =      // used by HELLO.CPP and BOUNCE.CPP
  6.     { 
  7.     RGB(0,   0, 0), 
  8.     RGB(255, 0,   0),
  9.     RGB(0, 255, 0), 
  10.     RGB(  0, 0, 255),
  11.     RGB(255, 255, 255) 
  12.     };
  13.  
  14. // Create one global CTheApp object to create and start the application
  15. CTheApp theApp;
  16.  
  17. // CMainWindow message map:
  18. BEGIN_MESSAGE_MAP(CMainWindow, CMDIFrameWnd)
  19.     ON_WM_CREATE()
  20.     ON_COMMAND(IDM_ABOUT, OnAbout)
  21.     ON_COMMAND(IDM_HELLO, OnNewHello)
  22.     ON_COMMAND(IDM_BOUNCE, OnNewBounce)
  23.     ON_COMMAND(IDM_FILEWIN, OnNewFileWin)
  24.     ON_COMMAND(IDM_CASCADE, MDICascade)
  25.     ON_COMMAND(IDM_TILE, MDITile)
  26.     ON_COMMAND(IDM_NEXT, MDINext)
  27.     ON_COMMAND(IDM_ARRANGE, MDIIconArrange)
  28.     ON_COMMAND(IDM_EXIT, OnExit)
  29.     ON_COMMAND(IDM_BUTTON_TEST, OnButtonTestDlg)
  30.     ON_MESSAGE(WM_CHILDDESTROY, OnChildDestroy)
  31. END_MESSAGE_MAP()
  32.  
  33.  
  34. CMainWindow::CMainWindow(void)
  35.     {
  36.     VERIFY(LoadAccelTable("ViewerAccel"));
  37.     Create(NULL, "MDI Viewer", WS_OVERLAPPEDWINDOW, rectDefault, 
  38.            NULL, "Init");
  39.     }
  40.  
  41. // OnCreate: Load app's initial MDI frame menu and create an MDI client
  42. int CMainWindow::OnCreate(LPCREATESTRUCT lpCreateStruct)
  43.     { 
  44.     m_pMenuInit = new CMenu();
  45.     m_pMenuInit->LoadMenu("Init");
  46.     CreateClient(lpCreateStruct, m_pMenuInit->GetSubMenu(0));
  47.     return 0;
  48.     }
  49.  
  50. // OnAbout: Display app's about box (defined in about.dlg).
  51. void CMainWindow::OnAbout(void)
  52.     {
  53.     CDialog about("AboutBox", this);
  54.     about.DoModal();
  55.     }
  56.  
  57. // OnNewHello: Create a new Hello child window.
  58. void CMainWindow::OnNewHello(void)
  59.     {
  60.     CHelloWin *pHelloWnd = new CHelloWin;
  61.  
  62.     if(!pHelloWnd->Create("Hello", 
  63.         (WS_CHILD | WS_VISIBLE | WS_OVERLAPPEDWINDOW),
  64.         rectDefault, this))
  65.         {
  66.         delete pHelloWnd;       // HWND not created
  67.         return;
  68.         }
  69.     pHelloWnd->ShowWindow(SW_SHOW);
  70.     // the default PostNcDestroy handler will delete this object when destroyed
  71.     }
  72.  
  73. // OnNewBounce: Create a new Bounce child window.
  74. void CMainWindow::OnNewBounce(void)
  75.     {
  76.     CBounceWin *pBounceWnd = new CBounceWin;
  77.     if(!pBounceWnd->Create("Bounce", 
  78.         (WS_CHILD | WS_VISIBLE | WS_OVERLAPPEDWINDOW),
  79.         rectDefault, this))
  80.         {
  81.         delete pBounceWnd;      // HWND not created
  82.         return;
  83.         }
  84.     pBounceWnd->ShowWindow(SW_SHOW);
  85.     // the default PostNcDestroy handler will delete this object when destroyed
  86.     }
  87.  
  88.  
  89. // OnNewFileWin: 
  90. void CMainWindow::OnNewFileWin(void)
  91.        {
  92.     CFileWin *pCFileWin = new CFileWin;
  93.  
  94.     if(pCFileWin->Open())
  95.         {
  96.         if(!pCFileWin->Create(NULL,"FileWin"))
  97.                {
  98.             delete pCFileWin;
  99.             return;
  100.                }
  101.         else
  102.             pCFileWin->ShowWindow(SW_SHOW);
  103.         }
  104.        }
  105.  
  106.  
  107. // OnChildDestroy:
  108. // This handler is triggered when a CBounceWin, CFileWnd or CHelloWin 
  109. // destroys itself -- the default implementation here does nothing but could
  110. // be customized to do additional work.
  111. //
  112. LONG CMainWindow::OnChildDestroy(UINT /*hWnd*/, LONG /* lParam */)
  113.     {
  114.     return 0;
  115.     }
  116.  
  117. // Destructor: Destroy all existing child windows.
  118. CMainWindow::~CMainWindow(void)
  119.     {
  120.     delete m_pMenuInit;
  121.     }
  122.  
  123. // OnExit: Exit the application.
  124. void CMainWindow::OnExit(void)
  125.     {
  126.     DestroyWindow();
  127.     }
  128.  
  129. void CMainWindow::OnButtonTestDlg()
  130.     {
  131.     CButtonTestDlg dlg;
  132.     dlg.DoModal();
  133.     }
  134.  
  135. // InitInstance:
  136. // Create and display the application main frame window
  137. //
  138. BOOL CTheApp::InitInstance(void)
  139.     {
  140.     SetDialogBkColor();
  141.  
  142.     m_pMainWnd = new CMainWindow();
  143.     m_pMainWnd->ShowWindow(m_nCmdShow);
  144.     m_pMainWnd->UpdateWindow();
  145.     return TRUE;
  146.     }
  147.  
  148.